package com.gxy.learn.design.model.construction.combination;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 菜单类  树枝节点角色
 * @author: gaoxueyong
 * @Date: 2022/11/7 21:40
 */
@Slf4j
public class Menu extends MenuComponent{

    private List<MenuComponent> menuComponentList = new ArrayList<>();

    public Menu(String name,int level) {
        super(name,level);
    }

    /**
     * 打印菜单名称方法（包含子菜单和子菜单项）
     *
     * @return void
     * @Author gaoxueyong
     * @Date 9:39 下午 2022/11/7
     * @Param []
     **/
    @Override
    public void print() {
        for(int i=0;i<level;i++){
            System.out.print("--");
        }
//        打印菜单名称
        log.info(name);
//        打印子菜单项名称
        for (MenuComponent menuComponent : menuComponentList) {
            menuComponent.print();
        }
    }

    /**
     * 添加子菜单
     *
     * @param menuComponent
     * @return void
     * @Author gaoxueyong
     * @Date 9:35 下午 2022/11/7
     * @Param [menuComponent]
     */
    @Override
    public void add(MenuComponent menuComponent) {
        menuComponentList.add(menuComponent);
    }

    /**
     * 移除子菜单
     *
     * @param menuComponent
     * @return void
     * @Author gaoxueyong
     * @Date 9:35 下午 2022/11/7
     * @Param [menuComponent]
     */
    @Override
    public void remove(MenuComponent menuComponent) {
        menuComponentList.remove(menuComponent);
    }

    /**
     * 获取指定菜单
     *
     * @param index
     * @return com.gxy.learn.design.model.construction.combination.MenuComponent
     * @Author gaoxueyong
     * @Date 9:38 下午 2022/11/7
     * @Param [index]
     */
    @Override
    public MenuComponent getChild(int index) {
        return menuComponentList.get(index);
    }
}
